var citydaypaikeCheckedItems;
var data_data;
function getcitydaypaikeData() {
    
    
    
	var startDate = $("#citydaypaikeStartDate").val();
	var endDate = $("#citydaypaikeEndDate").val();
    
    
        
    var osID = document.getElementById("citydaypaikeOS").options[document.getElementById("citydaypaikeOS").selectedIndex].value;
    var typeID = document.getElementById("citydaypaikeType").options[document.getElementById("citydaypaikeType").selectedIndex].value;
    var _limit = document.getElementById("citydaypaikeLimit").options[document.getElementById("citydaypaikeLimit").selectedIndex].value;
    
   

	$(".citydaypaikeChart").html("");
	if (startDate != "" && endDate != "")
	{
		var start = new Date();
		var end = new Date();

		//统计项
		var items = document.getElementsByName("citydaypaikeCheckbox");
		citydaypaikeCheckedItems = new Array();
		for(var i=0;i<items.length;i++) {
			if (items[i].checked)
			{
				citydaypaikeCheckedItems.push(items[i].value);
			}
		}

		if(citydaypaikeCheckedItems.length > 0) {


			jQuery('#body-wrapper').showLoading();
			start.setFullYear(startDate.substring(0,4), startDate.substring(5,7)-1, startDate.substring(8,10));
			end.setFullYear(endDate.substring(0,4), endDate.substring(5,7)-1 ,endDate.substring(8,10));

			days = parseInt((end - start)/1000/60/60/24)+1;

			var APIurl = "/client/citydaypaike?staDate="+startDate+"&pd="+days;
	        
            
            if (osID != ""){
				APIurl += "&os="+osID;
            }
			if (typeID != ""){
				APIurl += "&dt="+typeID;
            }
            if (_limit != ""){
				APIurl += "&limit="+_limit;
            }
            

			
			$.ajax({
				type: "GET",
				url: APIurl,
				dataType : "json",
				jsonnp: "callback",
				success:function(data,textStatus){ loadcitydaypaikeData(data)}
			});
            
            
            $.ajax({
  url: APIurl,
  type: "POST",
  data: "username="+login_username,
success: function(msg){
   //alert('ok');
}
});
            
		}
		else {
			alert("请选择至少一个统计项");
		}

	}
	else {
		alert("请选择时间区域");
	}
}


var citydaypaikeTabArr, citydaypaikeDetailArr, citydaypaikeSumArr, citydaypaikeDateArr, MainSubTitle;
function loadcitydaypaikeData(data) {
    
    var osID = document.getElementById("citydaypaikeOS").options[document.getElementById("citydaypaikeOS").selectedIndex].value;
    var typeID = document.getElementById("citydaypaikeType").options[document.getElementById("citydaypaikeType").selectedIndex].value;
    
    data_data = data;
	var tab = "";
	var startDate = $("#citydaypaikeStartDate").val();
	var endDate = $("#citydaypaikeEndDate").val();
	MainSubTitle = startDate.replace(/\//g, "-") + " 至 " + endDate.replace(/\//g, "-");
	jQuery('#body-wrapper').hideLoading();	


	citydaypaikeTabArr = new Array();
	citydaypaikeDetailArr = new Array();
	citydaypaikeSumArr = new Array();
	citydaypaikeDateArr = new Array();

			//显示选择Tab
			
            if(osID==""){

            genTabscitydaypaike("citydaypaike", "citydaypaikeOS", citydaypaikeTabArr, citydaypaikeDetailArr, citydaypaikeSumArr, citydaypaikeCheckedItems,0);
        }else if(typeID == ""){

            genTabscitydaypaike("citydaypaike", "citydaypaikeType", citydaypaikeTabArr, citydaypaikeDetailArr, citydaypaikeSumArr, citydaypaikeCheckedItems,0);
        }else{ genTabscitydaypaike("citydaypaike","", citydaypaikeTabArr, citydaypaikeDetailArr, citydaypaikeSumArr, citydaypaikeCheckedItems,0);  }
			
            
            //读取数据
            
        if ($("#citydaypaikePieTab").hasClass("selbitem")){
            
			changeChartType('citydaypaike', 'Pie');
        }
        
        if ($("#citydaypaikeTableTab").hasClass("selbitem")){
            
			changeChartType('citydaypaike','Table');
        }
        
        if (!$("#citydaypaikeTableTab").hasClass("selbitem") && !$("#citydaypaikePieTab").hasClass("selbitem")){
            
			changeChartType('citydaypaike','Table');
        }
        
        
        
        //生成表格
        genTop10Tablecitydaypaike("citydaypaikeTable", valueFullNameArr(citydaypaikeCheckedItems), citydaypaikeTabArr, data['All']['mtable'], data['All']['gtable']);
        
        //生成饼图
        genzhutucity("citydaypaikePie",data['All']['bingtucityx'],data['All']['bingtucityy'],data['All']['bingtuprovx'],data['All']['bingtuprovy']);
        
		
	
}

function changecitypaikeTab(cname){
        
    
    $(".citypaikezhuanyong").hide();
    $("#citydaypaike"+cname).show();
        
            
    $(".bitemvideo").removeClass("selbitem");
	$("#citypaikeTab"+cname).addClass("selbitem");


}

function changecitydaypaikeTab(tabName,optionName) {
	
        

        
        
        
        
        

    
    
    
	$(".bitem").removeClass("selbitem");
	$("#citydaypaikeTab"+tabName).addClass("selbitem");	
    
    
    //生成表格
        genTop10Tablecitydaypaike("citydaypaikeTable", valueFullNameArr(citydaypaikeCheckedItems), citydaypaikeTabArr,data_data[tabName]['mtable'], data_data[tabName]['gtable']);
        
        //生成饼图
        genzhutucity("citydaypaikePie",data_data[tabName]['bingtucityx'],data_data[tabName]['bingtucityy'],data_data[tabName]['bingtuprovx'],data_data[tabName]['bingtuprovy']);
    
    
    
	
}



